package com.atguigu.day16.exer.e1;

import org.junit.Test;

import java.util.Arrays;


/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/19 10:08
 * @注释
 */
public class StringTest {
    @Test
    public void test01(){
        //判断是否为空
        String str = " ";
        boolean empty = str.isEmpty();
        System.out.println(empty);
    }
    @Test
    public void test02(){
        //判断字符数量
        String str = "123456789";
        int length = str.length();
        System.out.println(length);
    }
    @Test
    public void test03(){
        //转换大小写

        //大写转小写
        String str = "ABCabc123";
        String lowerCase = str.toLowerCase();
        System.out.println(lowerCase);

        //小写转大写
        String upperCase = str.toUpperCase();
        System.out.println(upperCase);
    }
    @Test
    public void test04(){
        //拼接字符串
        String str = "abc";
        String str1 = "def";
        String concat = str.concat(str1);
        System.out.println(concat);
    }
    @Test
    public void test05(){
        //忽略大小写比较内容
        String str = "Abc";
        String str1 = "ABc";
        boolean b = str.equalsIgnoreCase(str1);
        System.out.println(b);
    }
    @Test
    public void test06(){
        //去除两边空白
        String str = "   a   a   a   a   a   ";
        System.out.println(str);
        String trim = str.trim();
        System.out.println("-->" + trim + "<--");
    }
    @Test
    public void test07(){
        //匹配字符
        String str = "aoahfaoihao";
        String s = "";//定义一个空字符串用来记录新字符串
        //遍历去掉"a"之后的字符串并拼凑在一起
        for (String a : str.split("a")) {
            s += a;
        }
        System.out.println(s);
    }
    @Test
    public void test08(){
        //指定元素第一次出现的下标
        String str = "afaafiawfaonaoifnaoi";
        int a = str.indexOf("a");
        System.out.println(a);
        //指定元素最后一次出现的下标
        int a1 = str.lastIndexOf("a");
        System.out.println(a1);
    }
    @Test
    public void test09(){
        //遍历字符串
        String str = "aofiainga";
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            System.out.println(c);
        }
    }
    @Test
    public void test10(){
        //给字符串排序--->首先转换为字符数组--->然后对字符数组进行排序后输出
        String str = "aadaionoaindaoino";
        char[] arr = str.toCharArray();
        Arrays.sort(arr);
        System.out.println(arr);
    }
    @Test
    public void test11(){
         int i = 122;
         Integer i1 = 122;
         System.out.println(i == i1);
    }
}
